package heap;

import java.util.Comparator;

import org.junit.Test;

public class HeapTest {
	@Test
	public void testBinaryHeap() throws Exception {
		Integer[] data = new Integer[]{13, 36, 18, 24, 43, 47};
		Heap<Integer> heap = new BinaryHeap<>(new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			}
		});
		int k = 3;
		for (int i = 0; i < data.length; i++) {
			if (heap.size() < k) {
				heap.add(data[i]);
			} else if (heap.get() < data[i]) {
				heap.replace(data[i]);
			}
		}
		System.out.println(heap);
	}
	
	@Test
	public void testPriorityQueue() throws Exception {
		PriorityQueue<Person> queue = new PriorityQueue<>();
		queue.enQueue(new Person("jack", 10));
		queue.enQueue(new Person("jack", 5));
		queue.enQueue(new Person("jack", 15));
		queue.enQueue(new Person("jack", 30));
		queue.enQueue(new Person("jack", 20));
		System.out.println(queue.deQueue());
		System.out.println(queue.deQueue());
		System.out.println(queue.deQueue());
		System.out.println(queue.deQueue());
	}
}
